﻿using System;
using System.Collections.Generic;
using System.Net;

namespace NewRetail.Application.Utility.MemoryCommon
{
    public interface ICacheHelper
    {
        /// <summary>
        /// 验证缓存项是否存在
        /// </summary>
        /// <param name="key">缓存Key</param>
        /// <returns></returns>
        bool Exists(string key);

        ///// <summary>
        ///// 验证缓存项是否存在（异步方式）
        ///// </summary>
        ///// <param name="key">缓存Key</param>
        ///// <returns></returns>
        //Task<bool> ExistsAsync(string key);

        /// <summary>
        /// 获取缓存
        /// </summary>
        /// <param name="key">缓存Key</param>
        /// <returns></returns>
        T GetCache<T>(string key) where T : class;

        /// <summary>
        /// 获取缓存
        /// </summary>
        /// <param name="key">缓存Key</param>
        /// <returns></returns>
        object GetCache(string key);

        /// <summary>
        /// 获取缓存集合
        /// </summary>
        /// <param name="keys">缓存Key集合</param>
        /// <returns></returns>
        IDictionary<string, object> GetCacheAll(IEnumerable<string> keys);

        /// <summary>
        /// 添加缓存
        /// </summary>
        /// <param name="key">缓存Key</param>
        /// <param name="value">缓存Value</param>
        void SetCache(string key, object value);

        void SetCache(string key, object value, DateTimeOffset expiressAbsoulte);//设置绝对时间过期

        void SetSlidingCache(string key, object value, TimeSpan t);  //设置滑动过期， 因redis暂未找到自带的滑动过期类的API，暂无需实现该接口

        /// <summary>
        /// 删除缓存
        /// </summary>
        /// <param name="key">缓存Key</param>
        bool RemoveCache(string key);

        /// <summary>
        /// 批量删除缓存
        /// </summary>
        /// <param name="key">缓存Key集合</param>
        /// <returns></returns>
        void RemoveCacheAll(IEnumerable<string> keys);
        /// <summary>
        /// 移除全部缓存
        /// </summary>
        void RemoveCacheAll();
        /// <summary>
        /// 获取所有缓存键
        /// </summary>
        /// <returns></returns>
        List<string> GetCacheKeys();

        void KeyMigrate(string key, EndPoint endPoint, int database, int timeountseconds);

        void Dispose();

        void GetMssages();

        void Publish(string msg);
    }
}
